(旧Siv3D) ham::SceneManager でお手軽シーンチェンジ
https://gyazo.com/6a38b7e692b0a7fb54a8c97b3dcd99d7
code:siv3d_scene.cpp
// こちらで詳しい解説がされています:
enum class SceneType
{
Empty,
Title,
Main,
};
struct GameData
{
void Fade(double t, bool fadeIn)
{
Graphics2D::SetStencilState(StencilState::Replace);
Graphics2D::SetStencilValue(1);
Circle(Window::Center(), (fadeIn ? t : 1 - t) * (Window::ClientRect().w) / 2.0 * 1.3).draw();
Graphics2D::SetStencilState(StencilState::Test(StencilFunc::NotEqual));
Window::ClientRect().draw(Palette::Black);
Graphics2D::SetStencilState(StencilState::Default);
}
};
using SceneMgr = SceneManager<SceneType, GameData>;
struct SceneEmpty : SceneMgr::Scene
{
void update() override {}
void draw() const override
{
Window::ClientRect().draw(Palette::Black);
}
void updateFadeIn(double t) override
{
// 即タイトルシーンへ
changeScene(SceneType::Title, 750, true);
}
};
struct SceneTitle : SceneMgr::Scene
{
void update() override
{
if (Input::MouseL.clicked)
{
changeScene(SceneType::Main, 750);
}
}
void draw() const override
{
Window::ClientRect().draw(Palette::Royalblue);
FontAsset(L"font")(L"TITLE").drawCenter(Window::Center(), Palette::White);
}
};
struct SceneMain : SceneMgr::Scene
{
void update() override
{
if (Input::MouseL.clicked)
{
changeScene(SceneType::Title, 750);
}
}
void draw() const override
{
Window::ClientRect().draw(Palette::Palevioletred);
FontAsset(L"font")(L"MAIN GAME SCENE").drawCenter(Window::Center(), Palette::White);
}
void drawFadeIn(double t) const override
{
draw();
m_data->Fade(t, true);
}
void drawFadeOut(double t) const override
{
draw();
m_data->Fade(t, false);
}
};
void Main()
{
Window::Resize(640, 480);
Graphics::SetBackground(Palette::Black);
FontAsset::Register(L"font", 40, Typeface::Bold);
SceneMgr sceneMgr;
sceneMgr.add<SceneEmpty>(SceneType::Empty);
sceneMgr.add<SceneTitle>(SceneType::Title);
sceneMgr.add<SceneMain>(SceneType::Main);
while (System::Update())
{
if (!sceneMgr.updateAndDraw())
{
break;
}
}
}